<template>
  <div class="p-2">

    <div class="mb-[10px]">
      <el-card>
        <el-form
          ref="queryFormRef"
          :model="queryParams"
          :inline="true"
          label-width="auto"
        >
          <el-form-item
            label="创建时间"
          >
            <el-date-picker
              v-model="dateRange"
              value-format="YYYY-MM-DD"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              style="width: 240px"
            ></el-date-picker>
          </el-form-item>
          <el-form-item
            label="服务商名称"
            prop="name"
          >
            <el-input
              v-model="queryParams.name"
              placeholder="请输入服务商名称"
              clearable
              @keyup.enter="handleQuery"
            />
          </el-form-item>
          <el-form-item
            label="服务商编号"
            prop="name"
          >
            <el-input
              v-model="queryParams.no"
              placeholder="请输入服务商编号"
              clearable
              @keyup.enter="handleQuery"
            />
          </el-form-item>
          <el-form-item
            label="产品编号"
            prop="name"
          >
            <el-input
              v-model="queryParams.proNo"
              placeholder="请输入产品编号"
              clearable
              @keyup.enter="handleQuery"
            />
          </el-form-item>

          <el-form-item>
            <el-button
              type="primary"
              @click="handleQuery"
              icon="Search"
              v-hasPermi="['payment:proInfo:list']"
            >查询</el-button>
            <el-button
              @click="resetQuery"
              icon="Refresh"
            >重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
    <el-card>
      <el-table
        v-loading="loading"
        :data="agentList"
        border
      >
        <el-table-column
          label="创建时间"
          align="center"
          min-width="160"
          prop="createTime"
        />
        <el-table-column
          label="产品编号"
          align="center"
          min-width="160"
          prop="proNo"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="代理商名称"
          align="center"
          min-width="160"
          prop="channelName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="服务商名称"
          align="center"
          min-width="160"
          prop="serviceName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="服务商编号"
          align="center"
          min-width="160"
          prop="serviceNo"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="业务类型"
          align="center"
          min-width="160"
          prop="busType"
          :show-overflow-tooltip="true"
        >
          <template #default="scope">
            <dict-tag
              :options="wxfe_bus_type"
              :value="scope.row.busType"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="开票类型"
          align="center"
          min-width="160"
          prop="invoiceType"
          :show-overflow-tooltip="true"
        >
          <template #default="scope">
            <dict-tag
              :options="invoice_type"
              :value="scope.row.invoiceType"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="开票项目"
          align="center"
          min-width="160"
          prop="invoiceItems"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="费率(%)"
          align="center"
          min-width="160"
          prop="serviceCharge"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="计费模式"
          align="center"
          min-width="160"
          prop="chargeMode"
          :show-overflow-tooltip="true"
        >
          <template #default="scope">
            <dict-tag
              :options="charge_mode"
              :value="scope.row.chargeMode"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="到账方式"
          align="center"
          min-width="160"
          prop="settlementStyle"
          :show-overflow-tooltip="true"
        >
          <template #default="scope">
            <dict-tag
              :options="settlement_style"
              :value="scope.row.settlementStyle"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="单月发放上限(元)"
          align="center"
          min-width="160"
          prop="maxMonthStr"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="上架状态"
          align="center"
          min-width="160"
          prop="proStatus"
        >
          <template #default="scope">
            <dict-tag
              :options="pro_status"
              :value="scope.row.proStatus"
            />
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script setup name="productShop" lang="ts">
import api from '@/api/service/productShop';
import { ProductShopQuery, ProductShopVO } from '@/api/service/productShop/types';

const router = useRouter();
const { proxy } = getCurrentInstance() as ComponentInternalInstance;

const { wxfe_bus_type, invoice_type, charge_mode, settlement_style, pro_status } = toRefs<any>(
  proxy?.useDict('wxfe_bus_type', 'invoice_type', 'charge_mode', 'settlement_style', 'pro_status')
);

const agentList = ref<ProductShopVO[]>();
const loading = ref(true);
const total = ref(0);
const dateRange = ref<[DateModelType, DateModelType]>(['', '']);
const queryFormRef = ref<ElFormInstance>();
const queryParams = ref<ProductShopQuery>({
  pageNum: 1,
  pageSize: 10,
  startTime: '',
  endTime: '',
  name: '',
  no: '',
  proNo: ''
});

/** 查询代理商列表 */
const getList = async () => {
  loading.value = true;
  const res = await api.productShopList(proxy?.addDateRange(queryParams.value, dateRange.value));
  loading.value = false;
  agentList.value = res.rows;
  total.value = res.total;
};

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};
/** 重置按钮操作 */
const resetQuery = () => {
  dateRange.value = ['', ''];
  queryFormRef.value?.resetFields();
  queryParams.value.pageNum = 1;
  handleQuery();
};

onMounted(() => {
  getList(); // 初始化列表数据
});
</script>

<style lang="scss" scoped></style>
